package com.zhyt.intelligentpipeline.model;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.zhyt.intelligentpipeline.exception.CustomException;
import com.zhyt.intelligentpipeline.exception.ErrorBody;
import com.zhyt.intelligentpipeline.exception.ErrorCode;
import lombok.Data;
import org.springframework.http.HttpStatus;
import org.springframework.util.StringUtils;

import javax.validation.constraints.NotBlank;


@Data
@TableName("pipeline_tb")
public class Pipeline {
    @TableId
    String id;

    @TableField("initial_station")
    String initialStation;

    @TableField("end_station")
    String endStation;

    @TableField("diameter")
    String diameter;

    @TableField("wall_thickness")
    String wallThickness;

    @TableField("grade")
    String grade;

    @TableField("design_press")
    String designPress;

    @TableField("service_life")
    String serviceLife;

    @TableField("coatings_thickness")
    String coatingsThickness;

    @TableField("trunk_line")
    String trunkLine;

    public static void checkValue(Pipeline pipeline) {
        if(!StringUtils.hasText(pipeline.getEndStation())){
            throw CustomException.of(HttpStatus.BAD_REQUEST, new ErrorBody(500,"缺少管段的终点站"));
        }
        if(!StringUtils.hasText(pipeline.getInitialStation())){
            throw CustomException.of(HttpStatus.BAD_REQUEST, new ErrorBody(500,"缺少管段的起点站"));
        }
        if(!StringUtils.hasText(pipeline.getTrunkLine())){
            throw CustomException.of(HttpStatus.BAD_REQUEST, new ErrorBody(500,"缺少管段干线"));
        }

    }
}
